package ${basePackage}.controller;
import ${basePackage}.core.Result;
import ${basePackage}.core.ResultGenerator;
import ${basePackage}.model.${modelNameUpperCamel};
import ${basePackage}.service.${modelNameUpperCamel}Service;
import ${basePackage}.core.ValidationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
* Created by ${author} on ${date}.
*/
@RestController
@RequestMapping("/api/${baseRequestMapping}")
public class ${modelNameUpperCamel}Controller {
    @Autowired
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @PostMapping("/add")
    public Result add(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ValidationUtils.validate(${modelNameLowerCamel});
        ${modelNameLowerCamel}Service.addEntity(${modelNameLowerCamel});
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam String id) {
        ${modelNameLowerCamel}Service.deleteEntityById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ValidationUtils.validate(${modelNameLowerCamel});
        ${modelNameLowerCamel}Service.updateEntity(${modelNameLowerCamel});
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/getall")
    public Result getAll() {
        List<${modelNameUpperCamel}> ${modelNameLowerCamel}s = ${modelNameLowerCamel}Service.getAll();
        return ResultGenerator.genSuccessResult(${modelNameLowerCamel}s);
    }

    @PostMapping("/getid")
    public Result getEntityById(@RequestParam String id) {
        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.getEntityById(id);
        return ResultGenerator.genSuccessResult(${modelNameLowerCamel});
    }

    @PostMapping("/getpagelist")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<${modelNameUpperCamel}> ${modelNameLowerCamel}s = ${modelNameLowerCamel}Service.getAll();
        PageInfo pageInfo = new PageInfo(${modelNameLowerCamel}s);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    @PostMapping("/getallwhere")
    public Result getAllWhere(@RequestParam String wheresql) {
        List<${modelNameUpperCamel}> ${modelNameLowerCamel}s = ${modelNameLowerCamel}Service.getAllWhere(wheresql);
        return ResultGenerator.genSuccessResult(${modelNameLowerCamel}s);
    }

    @PostMapping("/batchinsert")
    public Result batchInsert(@RequestBody List<${modelNameUpperCamel}> ${modelNameLowerCamel}s ) {
        int inserts= ${modelNameLowerCamel}Service.batchInsert(${modelNameLowerCamel}s );
        return ResultGenerator.genSuccessResult(inserts);
        }

}
